<script>
    var page_list = "company_list";
    $(function() {
        $("body").layout();
        grid_init($("#grid"),{
            singleSelect: false,
            url:'slave/basis/findList.do',
            columns:[[
                { field: 'o.id', checkbox: true, title: 'ID',width: 80,hidden:'true'},
                { field: 'o.name', title: '企业名称',width: 200},
                { field: 'o.code', title: '金融代码',width: 100},
                { field: 'o.phone', title: '联系方式',width: 100},
                { field: 'o.address', title: '企业地址',width: 120},
                { field: 'o.line', title: '主营线路',width: 200},
                { field: 'o.url', title: 'url',width: 200},
                { field: 'o.f6AccountSet', title: 'F6账套名称',width: 100},
                { field: 't.administrativeDivisionName', title: '地区',width: 100},
                { field: 'o.createTime', title: '创建时间',width: 150},
                { field: '(SELECT COUNT(p.id) FROM `pre_accept_order` p WHERE p.`tenant_code` = o.code)', title: '下单次数',width: 100},
                { field: '(SELECT COUNT(p.id) FROM `pre_accept_order` p WHERE p.`tenant_code` = o.code AND p.`generate_flag` = 1)', title: '已转正次数',width: 100},
                { field: '(SELECT COUNT(w.with_draw_no) FROM `withdraw_money_main` w WHERE w.code = o.code)', title: '取款次数',width: 100},
                { field: 'o.makeOrderFlag', title: '下单状态',width: 90,formatter: function(value,row,index){
                    if (value=="1"){
                        return "启用";
                    } else if(value=="0"){
                        return "禁用";
                    }
                    return value;
                }},
                { field: 'o.withdrawFlag', title: '取款状态',width: 90,formatter: function(value,row,index){
                    if (value=="1"){
                        return "启用";
                    } else if(value=="0"){
                        return "禁用";
                    }
                    return value;
                }},
                { field: 'o.sendMsgFlag', title: '推送状态',width: 90,formatter: function(value,row,index){
                    if (value=="1"){
                        return "启用";
                    } else if(value=="0"){
                        return "禁用";
                    }
                    return value;
                }},
//                { field: 'o.imgLimit', title: '首页显示图片数量',width: 140},
                { field: 'o.businessStartTime', title: '开始营业时间',width: 120},
                { field: 'o.businessEndTime', title: '结束营业时间',width: 120},
                { field: 'o.lendingStartTime', title: '开始放款时间',width: 120},
                { field: 'o.lendingEndTime', title: '结束放款时间',width: 120},
                { field: 'o.isCustom', title: '是否定制',width: 90,formatter: function(value,row,index){
                    if (value=="1"){
                        return "是";
                    } else if(value=="0"){
                        return "否";
                    }
                    return value;
                }}
                 ]],
            _order:"o.createTime desc,o.code",
            _db:"slave",
            _append: [],//隐藏列
            _page: page_list,
            _table: "company as o left join tbadministrativedivision as t on o.administrativeDivisionCode = t.administrativeDivisionCode",//
            _exportTitle: false,
            _context_handle: [{
                text: "详情",
                icon: "icon-info",
                handle: function(index,row){
                    j_showWin({url:'logistics/company/info.html?keyId='+this.getFieldValue(row,"o.id"),
                        title:'公司信息',
                        iconCls: 'icon-form-info'})
                }
            },{
                text: "编辑",
                //auth: "update",
                icon: "icon-edit",
                handle: function(index,row){
                    j_showWin({url:'logistics/company/edit.html?keyId='+this.getFieldValue(row,"o.id"),title:'编辑公司信息',iconCls: 'icon-form-edit'})
                }
            }],
            toolbar: '#grid_toolbar',
            searchDiv: '#grid_search'
        });

        $("#btnBatchDelete").click(function(){
            initBatchDelete(grid_get("grid"),"project/batchDelete.do");
        })
    });

    //用户列表
    $('#user').inputgrid({
        idField:'o.id',
        textField:'o.loginName',
        searchField:['o.id','o.loginName'],//查询字段多字段匹配
        columns:[[
            { field: 'o.id', title: '员工编号'},
            { field: 'o.loginName', title: '员工姓名'},
            { field: 'o.realName', title: '真实姓名'}
        ]],
        _page: parent.page_list,
        _append: [],//隐藏列
        _table: "bs_user as o"
    });

    //金融代码
    $('#company').inputgrid({
        idField:'o.code',
        textField:'o.code',
        searchField:['o.code','o.name'],//查询字段多字段匹配
        columns:[[
            { field: 'o.code', title: '金融代码'},
            { field: 'o.name', title: '名称'},
            { field: 'o.address', title: '地址'}
        ]],
        _page: parent.page_list,
        _append: [],//隐藏列
        _table: "company as o",
        _db:"slave"
    });

    $('#synchroBtn').click(function(){
        j_showWin({url:'logistics/company/synchroCompany.html?batch=0', title:'同步公司信息', iconCls: 'icon-form-edit', width:600, height: 300});
    });

    $('#synchroBatchBtn').click(function(){
        j_showWin({url:'logistics/company/synchroCompany.html?batch=1', title:'同步公司信息-批量', iconCls: 'icon-form-edit', width:600, height: 300});
    });
</script>
<style>
    .datagrid-cell, .datagrid-cell-group, .datagrid-header-rownumber, .datagrid-cell-rownumber
    {
        text-overflow: ellipsis;
    }
</style>
<div id="grid_search" data-options="region:'north',height:'auto',hideExpandTool: true,hideCollapsedContent: false,collapsedContent:function(){return '查询条件(已隐藏)'}" style="border-top:none;border-left:none;border-right:none;" class="search-form">
    <!--<input type="hidden" name="o.deleteFlag" value="0"/>-->
    <div class="div-item">
        <div class="div-label">企业名称：</div>
        <input name="o.name" type="text" clear/>
    </div>
    <div class="div-item">
        <div class="div-label">金融代码：</div>
        <input type="text" id="company" name="o.code" clear/>
    </div>
    <div class="div-item">
        <div class="div-label">企业地址：</div>
        <input type="text" id="address" name="o.address" clear/>
    </div>
    <div class="div-item">
        <div class="div-label" style="width: 80px;">下单状态：</div>
        <select name="o.makeOrderFlag" id="makeOrderFlag" style="width: 60px;" value="${makeOrderFlag}" clear>
            <option value="" >所有</option>
            <option value="0" >禁用</option>
            <option value="1" >启用</option>
        </select>
    </div>
    <div class="div-item">
        <div class="div-label" style="width: 80px;">取款状态：</div>
        <select name="o.withdrawFlag" id="withdrawFlag" style="width: 60px;" value="${withdrawFlag}" clear>
            <option value="" >所有</option>
            <option value="0" >禁用</option>
            <option value="1" >启用</option>
        </select>
    </div>
    <div class="div-item">
        <div class="div-label" style="width: 80px;">推送状态：</div>
        <select name="o.sendMsgFlag" id="sendMsgFlag" style="width: 60px;" value="${sendMsgFlag}" clear>
            <option value="" >所有</option>
            <option value="0" >禁用</option>
            <option value="1" >启用</option>
        </select>
    </div>
    <div class="div-item">
        <div> <button id="synchroBtn">腾云同步</button></div>
    </div>
    <div class="div-item">
        <div> <button id="synchroBatchBtn">腾云同步-批量</button></div>
    </div>
</div>
<div data-options="region:'center',title:false,border:false" id="divCenter" style="">
    <table id="grid"></table>
</div>
<div id="grid_toolbar" style="padding:3px;">
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'layout-button-up'" onclick="var button=$(this);if(button.linkbutton('options').iconCls=='layout-button-up'){$('body').layout('collapse','north');button.linkbutton({iconCls:'layout-button-down'})}else{$('body').layout('expand','north');button.linkbutton({iconCls:'layout-button-up'})}button.linkbutton('disable');setTimeout(function(){button.linkbutton('enable');},200)" style="float:right"></a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-help'" id="help" style="float:right"></a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-button-refresh'" onclick="grid_get('grid')[0].search(true)" style="float:right">重置</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'" onclick="grid_get('grid')[0].search()" style="float:right">查询</a>
</div>